﻿$(document).ready(function () {
    $(".plus").click(function () {
        //alert("Hello world from jquery");
        var targetID = $("#vote" + $(this).attr('id')).attr('id');
        //alert(targetID);
        //$("#"+targetID).text("haha");

        $.ajax({
            type:"POST",
            url: "/Vote/Vote",
            contentType:"application/json; charset=utf-8",
            data: JSON.stringify({
                PostID: $(this).attr('id'),
                Value:1
            }),
            success: function (result) {
                //alert("OK! " + result);
                $("#"+targetID).html(result);
            },
            error: function (result) {
                alert(result)
            }
        }
        );
    });

    $(".minus").click(function () {
        //alert("Hello world from jquery");
        var targetID = $("#vote" + $(this).attr('id')).attr('id');
        //alert(targetID);
        //$("#"+targetID).text("haha");

        $.ajax({
            type: "POST",
            url: "/Vote/Vote",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({
                PostID: $(this).attr('id'),
                Value: -1
            }),
            success: function (result) {
                //alert("OK! " + result);
                $("#" + targetID).html(result);
            },
            error: function (result) {
                alert(result)
            }
        });
    });

    $("#answerForm").submit(function () {
        var answerModel = {
            QuestionID: $("#QuestionID").val(),           
            PostContent: tinyMCE.get('PostContent').getContent(),//$("#Content").val(),
        };

        //alert($("#Content").length);

        $.ajax({
            type: "post",
            url: $(this).attr("action"),
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(
                answerModel
            ),
            success: function (result) {
                //alert("OK! " + result);
                window.location.replace("Details?questionID=" + result);
            },
            error: function (result) {
                alert('error')
            }
        });
        return false;
    });

});
function handelVoteError(ajaxContext) {
    //var response = ajaxContext.get_response();
    //var 
    alert("Error")
}